cmake_minimum_required(VERSION 3.5.0)

project(${PROJECT})

enable_testing()

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)

#file(STRINGS "${PROJECT_SOURCE_DIR}/VERSION" PROJECT_VERSION)
set(PROJECT_VERSION ${VERSION})

string(TIMESTAMP TIMEYYMMDD %Y%m%d)
string(TIMESTAMP TIMEyymmdd %Y-%m-%d)
string(TIMESTAMP TIMEHHMMSS %H:%M:%S)
set(APP_VERSION "${PROJECT_VERSION} ${TIMEyymmdd} ${TIMEHHMMSS}")
add_definitions(-DAPPVERSION=\"${APP_VERSION}\")
add_definitions(-DAPPNAME=\"${PROJECT_NAME}\")

message(STATUS "platform:${PLATFORM}")

configure_file(version.h ${CMAKE_CURRENT_SOURCE_DIR}/src/common/version.h @ONLY)

execute_process(COMMAND make clean -C ${CMAKE_CURRENT_SOURCE_DIR}/makefile/euler)

execute_process(COMMAND make -j4 -C ${CMAKE_CURRENT_SOURCE_DIR}/makefile/euler)

#add_custom_target(build_target ALL 
#		COMMAND ${CMAKE_MAKE_PROGRAM}
#		WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/makefile/euler
#		COMMENT "datacenter makefile target")

add_subdirectory(config)
add_subdirectory(out)
add_subdirectory(lib)

set(CPACK_SOURCE_IGNORE_FILES "${PROJECT_BINARY_DIR}/;/.vscode/;/.cache/;/.gitignore")
#package 
set(CPACK_GENERATOR "TGZ")
set(CPACK_SOURCE_GENERATOR "TGZ")
set(CPACK_SET_DESTDIR OFF)  
set(CPACK_PACKAGE_DIRECTORY "package")
set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}")
#set(CPACK_PACKAGE_NAME "${PROJECT_NAME}")
set(CPACK_SOURCE_PACKAGE_FILE_NAME "code_${PROJECT_NAME}_${PROJECT_VERSION}-${TIMEYYMMDD}")
include(CPack)

message(STATUS "CMake ${CMAKE_VERSION} successfully configured ${PROJECT_NAME} using ${CMAKE_GENERATOR} generator")
message(STATUS "${PROJECT_NAME} package version: ${PROJECT_VERSION}")
message(STATUS "[cmake] Installation target path: ${CMAKE_INSTALL_PREFIX}")
if(CMAKE_TOOLCHAIN_FILE)
	message(STATUS "[cmake] Use toolchain file:		${CMAKE_TOOLCHAIN_FILE}")
endif()
message(STATUS "[cmake] Build for OS type:      ${CMAKE_SYSTEM_NAME}")
message(STATUS "[cmake] Build for OS version:   ${CMAKE_SYSTEM_VERSION}")
message(STATUS "[cmake] Build for CPU type:     ${CMAKE_SYSTEM_PROCESSOR}")
message(STATUS "[cmake] Build type:             ${CMAKE_BUILD_TYPE}")
string(TOUPPER "${CMAKE_BUILD_TYPE}" BUILD_TYPE)
message(STATUS "[cmake] Build with cxx flags:   ${CMAKE_CXX_FLAGS_${BUILD_TYPE}} ${CMAKE_CXX_FLAGS}")
message(STATUS "[cmake] Build with c flags:     ${CMAKE_C_FLAGS_${BUILD_TYPE}} ${CMAKE_C_FLAGS}")